<?php
abstract class Object{
	
	var $errors=array();
	public static $type=array("boolean","integer","double","string","array","object","null");
	
	function set($var,$value){
		$this->$var=$value;	
	}
	
	function get($property,$default=false){
		$var=$default;
		if(isset($this->$property)){
			$var= $this->$property;
		}
		return $var;
	}
	
	function getPropertyType($var){
		$type=null;
		if(isset($this->$var)){
			$type=gettype  ( $this->$var  );
		}
		return $type;
	}
	

	
	function isString($var){
		return (is_string($var));	
	}
	
	function isNumber($var){
		return (is_numeric($var));	
	}
	
	function isArray($var){
		return is_array($var);
	}
	
	function isObject($var){
		return is_object($var);
	}
	
	function typeCheck($var,$expected=null){
		$type=gettype($var);
		if($expected!=null){
			if(array_search($expected,self::$type)===false)
				return false;
			return true;
		}
		return $type;
	}
	
	function setError($code="",$msg){
		if($code!="")
			$this->errors[$code]=$msg;
		else
			$this->errors[]=$msg;
	}
	
	function getError($code=null){
		if($code==null){
			return $this->errors;
		}
		if(isset($this->errors[$code])){
			return $this->errors[$code];
		}
		return false;
	}
	
	
	
	function clearError($code){
		if(isset($this->errors[$code])){
			$temp=$this->errors[$code];
			unset($this->errors[$code]);
			return $temp;
		}
		return false;
	}
	
	function arrayToObject($array){
		$success=false;
		if(is_array($array)){
			foreach($array as $key=>$value){
				if($this->isNumber($key)) continue;
				if($this->isString($value)||$this->isNumber($value))
					if (ereg ("/s", $value)) continue;
				$this->$key=$value;	
			}
			$success=true;
		}	
		return $success;
	}
	

}
?>